package servlet;

import bean.Result;
import biz.ShopBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "SearchqueryServlet", value = "/SearchqueryServlet.s")
public class SearchqueryServlet extends HttpServlet {
    private ShopBiz biz = new ShopBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Result result;
        try{
            // 传数据
            String type = request.getParameter("type");// 条件查询的类型
            String spage = request.getParameter("spage");// 页数
            String company = request.getParameter("company");
            String order = request.getParameter("order");

            Map<String, Object> data = biz.searchquery(spage,company,type,order);
            result = new Result(1, "成功!", data);// 返回前台
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e);
            result = new Result(0, "显示失败!", null);
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
